<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="bbs.*,core.*,util.*" %>
<%@ include file="/WEB-INF/include/checkUser.jsp" %>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/include/header.jsp" %>
<script>
    $(function() {
        if (window.parent) {
            var h = $("html").height();
            $('iframe[src*=boardEdit1]', window.parent.document).css("height", h);
        }
    });
</script>
</head>
<%
    String errMsg = null,infoMsg = null;

    RequestParameter param = new RequestParameter(request);
    int boardId = param.getInt("bid", 0);
    BoardService boardService = new BoardService(request, boardId);
    if (boardService.canManageBoard() == false)
        new UnauthorizedAccessException("게시판 관리 권한 없음");

    Board board = BoardDAO.selectById(boardId);
    String title = param.getString("title", board.getTitle());
    if (request.getMethod().equals("POST")) {
        if (title.length() >= 2) {
            BoardDAO.updateTitle(boardId, title);
            infoMsg = "저장되었습니다";
        }
        else errMsg = "제목이 너무 짧습니다";
    }
%>
<body>

<h3>제목</h3>
<form method="post" class="form-inline">
    <input type="hidden" name="id" value="<%=boardId%>" />
    <input type="text" name="title" value="<%=title%>" />
    <button type="submit" class="btn">
        <i class="icon-hdd"></i> 제목 저장
    </button>
</form>

<% if (errMsg != null) { %>
    <div class="alert alert-error"><%= errMsg %></div>
<% } %>
<% if (infoMsg != null) { %>
    <div class="alert alert-info"><%= infoMsg %></div>
<% } %>

</body>
</html>
